<template>
  <div>
    <el-input
      v-model="scName"
      placeholder="请输入供应商名称"
      size="small"
      :readonly="true"
    >
      <el-button slot="append" icon="el-icon-thumb" @click="handleReturn"
        >选择</el-button
      >
    </el-input>

    <el-dialog :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="100px" size="mini"
      >
      
        <el-form-item label="供应商名称" prop="supplierName">
          <el-input
            v-model="queryParams.supplierName"
            placeholder="请输入供应商名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input
            v-model="queryParams.contactPerson"
            placeholder="请输入联系人"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input
            v-model="queryParams.phone"
            placeholder="请输入手机号码"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      
        <el-form-item label="评级" prop="supplierGrade">
          <el-input-number
            v-model="queryParams.supplierGrade"
            controls-position="right"
            placeholder="请输入评级"
            :step="1"
            :min="0"
            :max="10"
            step-strictly
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="supplierList">
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-radio"
              @click="handleSelect(scope.row)"
              >选择</el-button
            >
          </template>
        </el-table-column>
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="ID" align="center" prop="id" width="55" />
        <el-table-column label="供应商编码"  align="center"   prop="supplierCode"     min-width="100px"       />
        <el-table-column label="供应商名称"  align="center"   prop="supplierName"     min-width="200px"       />
        <el-table-column label="联系人" align="center" prop="contactPerson" />
        <el-table-column label="手机号码" align="center" prop="phone" min-width="120px"/>
        <el-table-column label="评级" align="center" prop="supplierGrade" />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div>
</template>

<script>
import { listSupplier, getSupplier } from "@/api/supplier/supplier";

export default {
  name: "Supplier",
  components: {},
  props: {
    supplierProps: {
      id: null,
      supplierCode: null,
      supplierName: "",
      legalPerson: null,
      taxCode: null,
    },
  },
  computed: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "supplierGrade",
        isAsc: "desc"
      },
      // 总条数
      total: 0,
      supplierList: [],
      // 弹出层标题
      title: null,
      // 是否显示弹出层
      open: false,
      returnSupplier: this.supplierProps,
      scName: this.supplierProps.supplierName,
      
    };
  },
  created() {},
  methods: {
    handleReturn() {
      this.open = true;
      this.title = "选择供应商";
      this.getList();
    },
    getList() {
      this.loading = true;
      listSupplier(this.queryParams).then((response) => {
        this.supplierList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSelect(row) {
      // this.queryParams.supplierName=row.supplierName;
      // this.queryParams.supplierId=row.id;
      this.returnSupplier = row;
      this.scName = row.supplierName;
      this.open = false;
      this.$emit("update:supplierProps", row);
      this.$emit("input", row.supplierName);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
   
  },
};
</script>